export class SubmitButtonService {
    constructor(parent) {
        this.parent = parent;
    }

    getButtonState() {
        this.parent.logger.debug("InteractionSubmitButton getButtonState " + this.parent.currentState);
        return this.parent.currentState;
    }

    setVisible(enable) {
        this.parent.logger.debug("InteractionSubmitButton setVisible " + enable);
        if (enable) {
            this.parent.$view.css("visibility", "");
        } else {
            this.parent.$view.css("visibility", "hidden");
        }
    }

    setButtonState(state) {
        this.parent.Logger.debug("setButtonState " + state);
        this.parent._stateChanged(state);
    }

    onTimeOver() {
        this.parent.Logger.debug("onTimeOver");
        this.parent._unbindEvent();
        this.parent.$view.find('.submit_button').addClass('com_btn_disabled');
    }

    getState() {
        var state = {
            code: this.parent.currentState,
            tip: this.parent.result_tip
        };
        this.parent.Logger.debug("InteractionSubmitButton getState " + JSON.stringify(state));
        return state;
    }

    setState(state) {
        this.parent.Logger.debug("InteractionSubmitButton setState " + JSON.stringify(state));
        if (state.code) {
            if (state.code == SUBMIT_BUTTON_STATE_CODE.SUBMITTING && state.__isSubmitSucceed != undefined) {
                if (this.parent.canModify) {
                    this.parent._stateChanged(SUBMIT_BUTTON_STATE_CODE.CAN_MODIFY, true);
                } else {
                    if (state.__isSubmitSucceed) {
                        this.parent._stateChanged(SUBMIT_BUTTON_STATE_CODE.FINISH, true);
                    } else {
                        this.parent._stateChanged(SUBMIT_BUTTON_STATE_CODE.CAN_SUBMIT, true);
                    }
                }
            } else {
                //支持思维导图多次交互特性，状态恢复bug-99606、99658 修复
                if (state.code === SUBMIT_BUTTON_STATE_CODE.FINISH && state.__isSubmitSucceed != true) {
                    state.code = SUBMIT_BUTTON_STATE_CODE.CAN_NOT_SUBMIT;
                }

                this.parent._stateChanged(state.code, true);
            }
        }
        if (state.tip) {
            this.parent._tipChanged(state.tip);
        }
    }

    setLocationProperties(properties) {
        this.parent.languageKeySet = properties;
    }
}